package oop.core.view.listeners;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import oop.core.med.SkillMediatorFromHotkey;

public class ActiveSkillMouseListener implements MouseListener {
	/**
	 * This class listens for a mouse click even in the window displaying an
	 * avatar's active skills.  It then checks to see if the mouse click fell
	 * properly on a skill and then activates that skill
	 * 
	 * 
	 */
	private SkillMediatorFromHotkey skillMediatorFromHotkey;
	
	public void setSkillMediatorFromHotkey(SkillMediatorFromHotkey skillMediatorFromHotkey)
	{
		this.skillMediatorFromHotkey = skillMediatorFromHotkey;
	}
	
	@Override
	public void mousePressed(MouseEvent e) {
		int x = e.getX();
		int y = e.getY();
		
		int code = getCode(x, y);
		if(code == -1)
			return;
		System.out.println("Using skill: " + code);
		skillMediatorFromHotkey.useSkill( code );
		// Do something with code.
	}
	
	private int getCode(int x, int y)
	{
		if(x<50 || x>150)
			return -1;
		y -= 85;
		if(y < 15)
			return -1;
		
		int c = y - (y%15);
		if(c%2==1)
			return (y/30);
		else
			return -1;
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {	
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}
	
	@Override
	public void mouseReleased(MouseEvent e) {
	}
}
